package com.jt.proxy;

import com.jt.Mapper.UserMapper;

import com.jt.Service.UserService;
import com.jt.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("userService")
public class StaticProxy implements UserService {
    @Autowired//byType  byName
    //目的：对原有的方法进行扩展
    private UserMapper target;

    @Override
    public void add2(User user) {
        try {
            System.out.println("事务开始");
            target.add(user);
            System.out.println("事务结束");
        }catch (Exception e){
            e.printStackTrace();
            System.out.println("事务回滚");
        }
    }

    @Override
    public void deleteUser(User user) {
        try {
            System.out.println("事务开始");
            target.deleteUser(user);
            System.out.println("事务结束");
        }catch (Exception e){
            e.printStackTrace();
            System.out.println("事务回滚");
        }
    }
}


